'use strict';
var BaseController = Class.extend({

    $scope: null,

    //正则匹配服务中需要继承的Event
    findExtend: function(){
        var _regExp = /Event/;
        if(_regExp.test(arguments[0])){
            return true;
        }
        else{
            return false;
        }
    },

    //将继承的事件写入对象
    writeEvent: function(){
        var obj = new arguments[0];
        for(var key in obj.__proto__){
            //过滤底层服务eg: $timeout
            if(obj.__proto__[key]){
                this[key] = obj.__proto__[key];
            }
        }
    },

    init: function(scope){
        this.$scope = scope;
        this.defineListeners();
        this.defineScope();
        //判断控制器事件是否被继承
        if(this.inherited && this.inherited.isExtend){
            for(var key in this) {
                //匹配含有Event的事件
                if (this.findExtend(key)) {
                    //写入事件
                    this.writeEvent(this.inherited.name);
                }
            }
        }
    },

    defineListeners: function(){
        this.$scope.$on('$destroy',this.destroy.bind(this));
    },

    defineScope: function(){
        //OVERRIDE
    },

    destroy: function(event){
        //OVERRIDE
    }
});

BaseController.$inject = ['$scope'];